package Aaaaaa;

import java.util.Scanner;

public class Main5 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int[] xiShu=new int[5];
        for(int i=0;i<5;i++){
            xiShu[i]=sc.nextInt();
        }
        int n=sc.nextInt();
        int[] res=new int[n];
        for(int i=0;i<n;i++){
            for(int j=0;j<5;j++){
                int score=sc.nextInt()*xiShu[j];
                res[i]+=score;
            }
        }
        int max=0;
        for(int i=0;i<n;i++){
            max=Math.max(max,res[i]);
        }
        System.out.println(max);
        int count=0;
        for(int i=0;i<n;i++){
            if(res[i]==max){
                count++;
            }
        }
        System.out.println(count);
        for(int i=0;i<n;i++){
            if(res[i]==max){
                System.out.println(i+1);
            }
        }
    }
}
